
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region StorageRole Model -(by fangyifeng at 2007-09-14 12:24:24)

	/// <summary>
	/// StorageRole object'StorageRole'.
	/// </summary>
	[Serializable]
	public class StorageRole : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected short _manageType;
		protected Guid _roleId;
		protected Storage _storage;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public StorageRole() { }

		public StorageRole( short manageType, Guid roleId, Storage storage )
		{
			this._manageType = manageType;
			this._roleId = roleId;
			this._storage = storage;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual short ManageType
		{
			get { return _manageType; }
			set { _manageType = value; }
		}

		public virtual Guid RoleId
		{
			get { return _roleId; }
			set { _roleId = value; }
		}

		public virtual Storage Storage
		{
			get { return _storage; }
			set { _storage = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is StorageRole))
				throw new InvalidCastException("This object is not of type StorageRole");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((StorageRole)obj).Id);
					break;
				case "ManageType":
					relativeValue = this.ManageType.CompareTo(((StorageRole)obj).ManageType);
					break;
				case "RoleId":
					relativeValue = this.RoleId.CompareTo(((StorageRole)obj).RoleId);
					break;
                default:
                    goto case "Id";
			}
            if (StorageRole.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
